package pure.ui 
{
	import pure.ui.groups.GroupBase;
	import pure.ui.groups.RadioButtonGroup
	import pure.ui.core.ToggleButton;
	import pure.ui.skins.ISkin;
	import pure.ui.skins.SkinColor;
	import flash.display.DisplayObjectContainer;
	import flash.events.*;
	import flash.geom.Point;

	/**
	 * 单选按钮
	 * @author Des
	 * <皮肤种类> ---- SelectableSkin
	 * 
	 * <TODO>使用RadioButtonGroup生成实例，不可单独使用！
	 */
	
public class RadioButton extends ToggleButton 
{
	public function RadioButton(x:Number, y:Number,  size:Point, skin:ISkin,hasLabel:Boolean ) 
	{
		super(x, y, size, skin,hasLabel);
	}
	
	
	
	
	
	
	
	
	
	/* ----------------------------------------------------    get / set    ----------------------------------------------------*/

	

	
	
	// 所在group
	override public function set group(value:GroupBase):void
	{
		if (!value is RadioButtonGroup)
		{
			throw new Error('RadioButton::group - 组合类型错误！');
		}
		_group = value;
	}

	
	
	

	/* ----------------------------------------------------    private    ----------------------------------------------------*/

	
	
	
	
	/**
	 * 缺省皮肤
	 * @param fillColor			颜色
	 * @param isSelected		是否选中状态
	 **/
	override protected function _drawSelectedFlag(fillColor:uint,isSelected:Boolean):void
	{
		_drawNoSkin(fillColor, 1);
		if (isSelected)
		{
			this.graphics.beginFill(0);
			this.graphics.drawCircle(0,0,(_width<_height?_width:_height)*0.25);
		}
	}
	
	/**
	 * 被选状态改变
	 **/
	override protected function _setSelectState():void
	{
		if (!this._selected)
		{
			var items:Array = group.items;
			var temp:RadioButton;
			var len:int = group.numItem;
			for (var i:int = 0; i < len; i++)
			{
				temp = items[i];
				if (temp.selected) 
				{
					temp.selected = false;
					break;
				}
			}
			group.selectedId = this.id;
			this.selected = true;
		}
	}
	
	/**
	 * 绘缺省皮肤
	 * @param fillColor			填充色
	 * @param thickness			边线粗细
	 * @param ellipse			四角内径
	 * @param alpha				透明度
	 * @param lineColor			边线颜色
	 **/
	override protected function _drawNoSkin(fillColor:uint,thickness:Number=1,ellipse:Number=4,alpha:Number=1, lineColor:uint = 0 ):void
	{
		this.graphics.clear();
		this.graphics.lineStyle(thickness,lineColor,alpha);
		this.graphics.beginFill(fillColor, alpha);
		this.graphics.drawEllipse(this._width*-0.5, this._height*-0.5,this._width,this._height);
		this._isClear = false;
	}
	
	/**
	 * 绘制
	 **/
	override protected function _draw():void
	{
		_selectView(SkinColor.Radio_OVER,SkinColor.Radio_OUT,SkinColor.Radio_SELECTED_OVER,SkinColor.Radio_SELECTED_OUT);
		super._draw();
	}
	
}

}